define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'facrm/customer/record/index',
                    del_url: 'facrm/customer/record/del'
                }
            });

            var contact  = $("#table");
            //在普通搜索渲染后
            contact.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $(".commonsearch-table select[name=scene_id]").val(4);
            
            });
            contact.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar',
                pageList: [10,100,999],
                queryParams: function (params) { // 请求服务器数据时发送的参数，可以在这里添加额外的查询参数，返回false则终止请求
                    //params.filter='{"customer_id":'+customer_id+'}';//只是查当前客户的联系人
                    return params
                },
                columns: [
                    [
                        {field: 'id', title: __('ID'),sortable: true},
                        {
                            field: 'scene_id',
                            title: __('记录场景'),
                            visible: false,
                            formatter: function (v,r) {
                                return scene_list[v];
                            },searchList: scene_list},
                        {
                            field: 'types_id',
                            title: __('客户名称'),
                            align: 'left',
                            formatter: function (value, row, index) {
                                if(!row.customer) return '-';
                                value='<a href="javascript:void(0);" data-url="facrm/customer/index/detail/ids/' + row.types_id
                                    +'" data-area="[&quot;100%&quot;,&quot;100%&quot;]" class="btn-dialog" data-title="'+ row.customer.name+'">'+ row.customer.name +'('+row.types_id+')'+'</a>';
                                return value;
                            },
                            addclass: 'selectpage',
                            extend: 'data-source="facrm/customer/index?filter=%7B\"scene_id\"%3A\"1\"%7D" data-field="name" data-orderBy="id desc"'},
                        {field: 'content', title: __('content'), operate: 'LIKE',align: 'left',},
                        {field: 'create_user.nickname', title: __('创建人'),operate:false,search:false},
                        {field: 'create_user_id', title: __('创建人'), visible:false,
							addclass: 'selectpage',
							extend: 'data-source="facrm/common/selectpage/model/admin?type=children" data-field="nickname" data-orderBy="id desc"'},

                        {field: 'create_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,
						extend: 'autocomplete="off"'},
                        {field: 'next_time', title: __('下次跟进'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,
						extend: 'autocomplete="off"'},
                        {field: 'record_type', title: __('跟进类型'),formatter: function (v,r) {
                                return record_type_list[v];
                            },searchList: record_type_list},
                        {field: 'operate', title: __('Operate'), table: contact,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'files',
                                    text: '附件',
                                    title: '查看附件',
                                    classname: 'btn btn-xs btn-success  btn-dialog',
                                    url:function (row) {
                                        return  'facrm/customer/record/files/types/'+row.types+'/ids/'+row.id;
                                    },
                                    hidden:function (row) {
                                        if (row.files.length<=0) return true;
                                    }

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }

                    ]
                ],
                //启用固定列
                fixedColumns: true,
                //固定右侧列数
                fixedRightNumber: 1,
                searchFormVisible:true, //打开搜索
            });
            // 初始化表格
            contact.bootstrapTable();
            Table.api.bindevent(contact);//当内容渲染完成后
            // 绑定TAB事件
            $('.panel-heading ul[data-field] li a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var field = $(this).closest("ul").data("field");
                var value = $(this).data("value");
                $(".commonsearch-table input[name="+field+"]").val(value);
                return false;
            });
        },
        add: function () {
            Controller.api.bindevent();
            if ("undefined" == typeof customer_id){
                customer_id=0;
            }
            Fast.api.ajax({
                url: 'facrm/fields/get_fields_html',
                data: {source: 'customer', 'id': customer_id,'tpl':"fields_12_2"}
            }, function (data) {
                $("#extend").html(data.html);
                Form.api.bindevent($("#extend"));
                return false;
            });
            $("#buttonshow").click(function () {
                var hiddeninfo= $("#hiddeninfo");
                hiddeninfo.toggle();
                if(hiddeninfo.css('display') === 'none'){
                    $(this).text("显示更多");
                }else{
                    $(this).text("隐藏信息");
                }
            });

            // 初始化表格参数配置

            Table.api.init({
                extend: {
                    index_url: 'facrm/customer/record/index/customer_id/'+customer_id,
                    contact_url:'facrm/customer/contacts/index/customer_id/'+customer_id,
                    business_url:'facrm/business/index/index/customer_id/'+customer_id,
                    contract_url:'facrm/customer/index/contractlist/customer_id/'+customer_id,
                    contractorder_url:'facrm/customer/index/orderlist/customer_id/'+customer_id,
                    receivables_url:'facrm/customer/index/receivableslist/customer_id/'+customer_id,
                    files_url:'facrm/customer/record/files/customer_id/'+customer_id,
                }
            });
            var table = $("#tableflow");
            //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
         
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar1',
                pageList: [10,100,999],
                columns: [
                    [
                        {field: 'scene_id',title: __('场景'),visible: false, searchList: {4:"全部"}},
                        {field: 'id', title: 'ID'},
                        {field: 'content', title: __('content'), operate: 'LIKE'},
                        {field: 'create_user.nickname', title: __('创建人'),operate:false},
                        {field: 'create_user_id', title: __('创建人'), visible:false,
							addclass: 'selectpage',
							extend: 'data-source="facrm/common/selectpage/model/admin?type=children" data-field="nickname" data-orderBy="id desc"'},

                        {field: 'create_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,
						extend: 'autocomplete="off"'},
                        {field: 'next_time', title: __('下次跟进'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,
						extend: 'autocomplete="off"'},

                        {field: 'files', title: __('附件'),formatter: function (v,row) {
                                if (v.length>0) return '<a href="facrm/customer/record/files/types/'+row.types+'/ids/'+row.id+'" class="btn btn-success btn-dialog btn-xs"><i class="fa fa-file-image-o"></i> ' + __('附件') + '</a>';
                            },operate: false},
                        {field: 'record_type', title: __('跟进类型'),formatter: function (v,r) {
                                return record_type_list[v];
                            },searchList: record_type_list},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            //联系人
            var contact  = $("#contact");
            contact.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("#forum select[name=scene_id]").val(4);
            });
            contact.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.contact_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar2',
               // commonSearch: false,
                 pageList: [10,100,999], pageList: [10,100,999],columns: [
                    [

                        {field: 'operate', title: __('Operate'), table: contact,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'edit1',
                                    text: '',
                                    title: '修改联系人',
                                    icon: 'fa fa-pencil',
                                    classname: 'btn btn-xs btn-success  btn-dialog',
                                    url: 'facrm/customer/contacts/edit',

                                },
                                {
                                    name: 'email',
                                    text: '@',
                                    title: '发送邮件',
                                    icon: '',
                                    classname: 'btn btn-xs btn-success   btn-click',
                                    click: function (data,row) {
                                        var that = this;
                                        var title = __('发邮件给联系人：')+row.name;
                                        var url = $(that).attr('href');

                                        var data = {types:'contacts',typesid:row.id};
                                        parent.Fast.api.open(url+"?data="+encodeURI(JSON.stringify(data)), title, data);
                                    },
                                    url:'facrm/apps/email/send',

                                },
                                {
                                    name: 'sms',
                                    text: '',
                                    title: '发送短息',
                                    icon: 'fa fa-envelope-o fa-fw',
                                    classname: 'btn btn-xs btn-success   btn-click',
                                    click: function (data,row) {
                                        var that = this;
                                        var title = __('发短息给联系人：')+row.name;
                                        var url = $(that).attr('href');

                                        var data = {types:'contacts',typesid:row.id};
                                        parent.Fast.api.open(url+"?data="+encodeURI(JSON.stringify(data)), title, data);
                                    },
                                    url:'facrm/apps/sms/send',

                                },
                                {   name: 'del1',
                                    text: '',
                                    title: '删除',
                                    confirm:"确认删除联系人？",
                                    icon: 'fa fa-trash',
                                    classname: 'btn btn-xs btn-danger  btn-ajax',
                                    url: 'facrm/customer/contacts/del',
                                    success:function(data,ret){
                                        $("a.btn-refresh").trigger("click");
                                    },
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {field: 'scene_id',title: __('场景'),visible: false, searchList: {4:"全部"}},
                        {field: 'name', title: __('姓名')},
                        {field: 'mobile', title: __('手机'), operate: 'LIKE', formatter: function (value, row, index) {
                                if (!value) return '-';
                                return '<a href="javascript:;" class="btn btn-success cloudcall btn-xs" data-field="mobile" data-typeid="'+
                                    row.id+'" data-type="customer_contacts" data-name="'+row.name+'"><i class="fa fa-phone"></i> ' +value + '</a>';
                            }},
                        {field: 'telephone', title: __('电话'), operate: 'LIKE', formatter: function (value, row, index) {
                                if (!value) return '-';
                                return '<a href="javascript:;" class="btn btn-success cloudcall btn-xs" data-field="telephone" data-typeid="'+
                                    row.id+'" data-type="customer_contacts" data-name="'+row.name+'"><i class="fa fa-phone"></i> ' +value + '</a>';
                            }},
                        {field: 'email', title: __('邮箱')},
                        {field: 'wechat', title: __('微信')},
                        {field: 'post', title: __('职务')},
                        {field: 'sex', title: __('性别'),formatter: Table.api.formatter.status, searchList: {0: __('女'), 1: __('男'), '-1': __('未知')}},
                        {field: 'decision', title: __('决策人'),formatter: Table.api.formatter.status, searchList: {0: __('否'), 1: __('是'), '-1': __('未知')}},
                        {field: 'detail_address', title: __('地址')},
                        {field: 'remark', title: __('备注')},
                        {field: 'next_time', title: __('下次联系'),formatter:Table.api.formatter.datetime, operate:'RANGE',addclass:'datetimerange' ,sortable: true,datetimeFormat: "YYYY-MM-DD",},
                        {field: 'create_time', title: __('创建时间'),formatter:Table.api.formatter.datetime, operate:'RANGE',addclass:'datetimerange' ,sortable: true,datetimeFormat: "YYYY-MM-DD",},


                    ]
                ],
            });
            // 初始化表格
            contact.bootstrapTable();
            Table.api.bindevent(contact);//当内容渲染完成后

            //商机
            var business  = $("#t-business");
            business.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("#business select[name=scene_id]").val(7);
            });
            business.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.business_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar-business',
                 pageList: [10,100,999],columns: [
                    [

                        {field: 'operate', title: __('Operate'), table: business,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'record',
                                    text: '跟进',
                                    title: '跟进',
                                    icon: 'fa fa-commenting-o',
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    url: 'facrm/business/record/add',
                                },
                                {
                                    name: 'edit1',
                                    text: '',
                                    title: '修改商机',
                                    icon: 'fa fa-pencil',
                                    classname: 'btn btn-xs btn-success  btn-dialog',
                                    url: 'facrm/business/index/edit',

                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {field: 'scene_id',title: __('场景'),visible: false, searchList: {7:"全部"}},
                        {field: 'name', title: __('商机名称'), operate: "LIKE"},
                        {field: 'money', title: __('客户预算'), operate: 'BETWEEN', sortable: true},
                        {field: 'total_price', title: __('产品价格'), operate: 'BETWEEN', sortable: true},
                        {field: 'remark', title: __('备注'), operate: 'LIKE'},
                        {
                            field: 'deal_time',
                            title: __('预计成交'),
                            formatter: Table.api.formatter.datetime,
                            datetimeFormat: "YYYY-MM-DD",
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
							extend: 'autocomplete="off"'
                        },
                        {
                            field: 'next_time',
                            title: __('下次跟进'),
                            formatter: Table.api.formatter.datetime,
                            datetimeFormat: "YYYY-MM-DD",
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
							extend: 'autocomplete="off"'
                        },
                        {field: 'create_user.nickname', title: __('创建人'), operate: false, search: false},
                        {field: 'create_user_id', title: __('创建人'), visible: false,
							addclass: 'selectpage',
							extend: 'data-source="facrm/common/selectpage/model/admin?type=children" data-field="nickname" data-orderBy="id desc"'},
                        {
                            field: 'update_time',
                            title: __('更新时间'),
                            formatter: Table.api.formatter.datetime,
                            datetimeFormat: "YYYY-MM-DD",
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
							extend: 'autocomplete="off"'
                        },
                        {
                            field: 'is_end',
                            title: __('Status'),
                            formatter: Table.api.formatter.status,
                            searchList: {1: __('已成交'), 0: __('未成交'), 2: __('失败'), 3: __('无效')}

                        },

                    ]
                ],
            });
            // 初始化表格
            business.bootstrapTable();
            Table.api.bindevent(business);//当内容渲染完成后

            //合同
            var contract  = $("#t-contract");
            contract.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.contract_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar-contract',
                commonSearch: false,
                 pageList: [10,100,999],columns: [
                    [
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: contract,
                            buttons: [
                                {
                                    name: 'payurl',
                                    text: '',
                                    title: __('线上续费收款码'),
                                    icon: 'fa fa-qrcode',
                                    classname: 'btn btn-xs btn-danger  btn-dialog',
                                    url: 'facrm/contract/index/payurl',
                                    hidden:function (row) {
                                        if (row.check_status == undefined||row.check_status!=2){
                                            return true;
                                        }
                                        if (!Config.payConfig||Config.payConfig.online_pay!='1'){
                                            return true;
                                        }
                                        //判断是否逾期
                                        var newtime = Math.round(new Date().getTime()/1000).toString();
                                        if (newtime<(row.end_time-(Config.payConfig.renew_day*86400))){
                                            return true;
                                        }
                                    },
                                    success:function () {
                                        $(".btn-refresh").trigger('click');
                                    }
                                },
                                {
                                    name: 'receivables',
                                    text: '详情',
                                    title: __('合同详情'),
                                    icon: '',
                                    classname: 'btn btn-info btn-dialog btn-xs',
                                    url: function(row){
                                        return 'facrm/customer/index/contract/customer_id/'+row.customer_id+'/ids/'+row.id;
                                    },
                                },
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                        },


                        {field: 'number', title: __('合同编号'), operate: "LIKE"},
                        {field: 'name', title: __('合同名称'), operate: "LIKE"},
                        {field: 'money', title: __('合同金额'), operate: 'BETWEEN', sortable: true},
                        {field: 'remark', title: __('备注'), operate: 'LIKE'},
                        {
                            field: 'start_time',
                            title: __('开始时间'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            datetimeFormat: "YYYY-MM-DD",
                            sortable: true,
							extend: 'autocomplete="off"'
                        },
                        {
                            field: 'end_time',
                            title: __('结束时间'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            datetimeFormat: "YYYY-MM-DD",
                            sortable: true,
							extend: 'autocomplete="off"'
                        },
                        {field: 'order_admin.nickname', title: __('签约人'), operate: false, search: false},
                        {field: 'order_admin_id', title: __('签约人'), visible: false},
                        {
                            field: 'check_status',
                            title: __('Status'),
                            formatter: Table.api.formatter.status,
                            searchList: {0: __('待审核'), 1: __('审核中'), 2: __('通过'),3: __('未通过')}
                        },

                    ]
                ],
            });
            // 初始化表格
            contract.bootstrapTable();
            Table.api.bindevent(contract);//当内容渲染完成后


            //新增订单
            var contract  = $("#t-contractorder");
            contract.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.contractorder_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar-contractorder',
                commonSearch: false,
                 pageList: [10,100,999],columns: [
                    [

                        {field: 'ordersn', title: __('订单号'), operate: "LIKE"},
                        {field: 'good_name', title: __('商品名'), operate:false},
                        {field: 'good_image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'number', title: __('数量'), operate: 'BETWEEN', sortable: true},
                        {field: 'oldmoney', title: __('原价')},
                        {field: 'money', title: __('价格'), operate: 'LIKE'},
                        {field: 'desc', title: __('备注'), operate: false, search: false},
                        {field: 'goin', title: __('来源')},
                        {field: 'timestamp', title: __('时间')},
                        {field: 'status_v', title: __('状态')},

                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'del1',
                                    text: '',
                                    title: '删除',
                                    confirm: "确认删除联系人？",
                                    icon: 'fa fa-trash',
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    url: 'facrm/customer/index/delorder',
                                    success: function (data, ret) {

                                    },
                                    visible: function (row) {

                                        if (row.status==1){
                                            return false;
                                        }else{
                                            return true;
                                        }

                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },


                    ]
                ],
            });
            // 初始化表格
            contract.bootstrapTable();
            Table.api.bindevent(contract);//当内容渲染完成后








            //回款
            var receivables  = $("#t-receivables");
            receivables.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.receivables_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar-receivables',
                commonSearch: false,
                 pageList: [10,100,999],columns: [
                    [
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: receivables,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [

                                {
                                    name: 'payurl',
                                    text: '',
                                    title: __('线上收款码'),
                                    icon: 'fa fa-qrcode',
                                    classname: 'btn btn-success btn-dialog btn-xs',
                                    url: 'facrm/contract/receivables/payurl',
                                    hidden:function (row) {
                                        if (row.pay_type == 1){
                                            return true;
                                        }
                                        if (row.pay_status == undefined||row.pay_status==1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'receivables',
                                    text: '详情',
                                    title: __('回款详情'),
                                    icon: '',
                                    classname: 'btn btn-info btn-dialog btn-xs',
                                    url: function(row){
                                        return 'facrm/customer/index/receivables/customer_id/'+row.customer_id+'/ids/'+row.id;
                                    },
                                },

                            ],
                        },

                        {field: 'number', title: __('回款编号'), operate: "LIKE"},
                        {field: 'contract.number', title: __('合同编号'), operate: "LIKE"},
                        {field: 'contract.name', title: __('合同名称'), operate: "LIKE"},
                        {field: 'money', title: __('回款金额'), operate: 'BETWEEN', sortable: true},
                        {field: 'remark', title: __('备注'), operate: 'LIKE'},
                        {
                            field: 'create_time',
                            title: __('创建时间'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
							extend: 'autocomplete="off"'
                        },
                        {
                            field: 'check_status',
                            title: __('Status'),
                            formatter: function (value, row, index) {
                                var check_status={0: __('待审核'), 1: __('审核中'), 2: __('审核通过'),3: __('审核未通过')};
                                var pay_status={1:'已付款',0:'未付款'};
                                var retrunstr='';
                                if(row['pay_type']==2){
                                    retrunstr='(在线'+pay_status[row['pay_status']]+')';
                                }else if(row['pay_type']==3){
                                    retrunstr='(续费)';
                                }
                                return check_status[row['check_status']]+retrunstr;
                            }

                        },

                    ]
                ],
            });
            // 初始化表格
            receivables.bootstrapTable();
            Table.api.bindevent(receivables);//当内容渲染完成后
            //附件
            var files  = $("#t-files");
            files.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.files_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#toolbar-files',
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: false,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false,
                //分页大小
                pageSize: 12,
                showColumns: false,
                showToggle: false,
                showExport: false,
                showSearch: false,
                pagination: false,
                columns: [
                    [
                        {field: 'url', title: __('预览'), formatter: Controller.api.formatter.thumb, operate: false},
                        {field: 'create_time', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,
							extend: 'autocomplete="off"'},

                    ]
                ],
            });
            //发邮件|发信息
            $(".btn-send-email,.btn-send-sms").click(function () {
                var that = this;
                var title = $(that).data('title') || $(that).attr("title") || __('操作');
                var url = $(that).data('url');
                var data = $(that).data() || {};
                delete data.title,data.url;
                parent.Fast.api.open(url+"?data="+encodeURI(JSON.stringify(data)), title, data);
            });
            //云呼

            $(document).on('click', ".cloudcall", function () {
                var that = this;
                var type = $(that).data('type');
                var typeid = $(that).data('typeid');
                var name = $(that).data('name');
                var field = $(that).data('field');

                Fast.api.ajax({
                    url: 'facrm/setting/cloudcall/call',
                    data: {type: type, typeid: typeid,field:field,name:name}
                }, function (data) {
                    Toastr.success("呼叫成功!");
                    return false;
                });
            });

            //下一个客户
            $(".btn-next").click(function () {
                Fast.api.ajax({
                    url: $(this).data('url'),
                    data: {}
                }, function (data) {
                    setTimeout("closetab()",'100');
                    Backend.api.addtabs('facrm/customer/record/add/ids/'+data.id,'跟进客户-'+data.name);

                    return false;
                });
            });



        },
        edit: function () {

        },

        files: function () {

        },
        calllog: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'facrm/customer/record/calllog'+(customer_id?"/customer_id/"+customer_id:""),
                    multi_url: '',
                    table: '',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                 pageList: [10,100,999],columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'admin_id', title: __('员工'),addclass: 'selectpage',
                            formatter: function (v, r) {
                                if (!r.admin) return '-';
                                return r.admin.nickname;
                            },
                            extend: 'data-source="facrm/common/selectpage/model/admin?type=all" data-field="nickname" data-orderBy="id desc"'},
                        {field: 'from_exten', title: __('坐席工号'), operate: "LIKE"},
                        {field: 'call_no', title: __('号码'), operate: "LIKE"},
                        {
                            field: 'status',
                            title: __('Status'),
                            formatter: Table.api.formatter.status,
                            searchList: {0: __('未同步'), 1: __('已同步'), '-1': __('未接通')}
                        },
                        {
                            field: 'record_file',
                            title: __('录音'),
                            operate: "LIKE",
                            align: 'left',
                            formatter: function (value, row, index) {
                                if (!value) return '-';

                                if (!value || row.status!=1) return '-';

                                return '<a  href="' + value
                                    + '" target="_blank" data-title="查看录音">查看录音</a>';
                            }
                        },
                        {field: 'call_time_length', title: __('通话时长(秒)'), operate: 'BETWEEN', sortable: true},
                        {
                            field: 'create_time',
                            title: __('创建时间'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'logdetail',
                                text: __('Detail'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'facrm/setting/cloudcall/logdetail'
                            }],
                            formatter: Table.api.formatter.operate,
                        }

                    ]
                ],
                //启用固定列
                fixedColumns: true,
                //固定右侧列数
                fixedRightNumber: 1,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },


        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"), function (data) {
                    $("#tableflow").bootstrapTable("refresh");
                    $("#record-content").val("");
                    return true;
                });
            }
            ,
            formatter: {
                thumb: function (value, row, index) {
                    var reg = /\.(png|jpg|gif|jpeg|webp)$/;
                    if (reg.test(row.url)) {
                        return '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + '" alt="" style="max-height:90px;max-width:120px"></a>';
                    } else {
                        return '<a href="' + row.fullurl + '" target="_blank"><img src="' + Fast.api.fixurl("ajax/icon") + "?suffix=" + row.imagetype + '" alt="" style="max-height:90px;max-width:120px"></a>';
                    }
                },
                url: function (value, row, index) {
                    return '<a href="' + row.fullurl + '" target="_blank" class="label bg-green">' + row.url + '</a>';
                },
                filename: function (value, row, index) {
                    return '<div style="width:180px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + Table.api.formatter.search.call(this, value, row, index) + '</div>';
                },
            }
        }
    };
    return Controller;
});
function  closetab(){
    top.window.$("ul.nav-addtabs li.active").prev().find(".close-tab").trigger("click");
}